#! _*_ coding:utf8 _*_
from django.db import models
import sys
reload(sys)
sys.setdefaultencoding('utf8')

CATEGORY_CHOICES = [
    (0, 'events'),
    (1, 'births'),
    (2, 'deaths'),
    (3, 'holidays'),
    (4, 'party'),  # 党史记录
]


# Create your models here.
class SDCategory(models.Model):
    """
    事件分属的类别
    """
    title = models.SmallIntegerField(choices=CATEGORY_CHOICES, default=0, verbose_name=u'类别名称')

    def __str__(self):
        return CATEGORY_CHOICES[self.title][1]


class SDEvent(models.Model):
    """
    发生的事件
    """
    category = models.ForeignKey(SDCategory, on_delete=models.SET_DEFAULT, default=0, verbose_name=u'类别')
    date_str = models.CharField(max_length=16, verbose_name=u'事件的日期')
    language = models.CharField(max_length=8, verbose_name=u'语言', default='zh')

    def __str__(self):
        return str(self.category) + ',' + self.date_str


class SDRichPart(models.Model):
    """
    每个事件的富文本组成部分
    """
    text = models.TextField(verbose_name=u'富文本内容')
    link = models.URLField(verbose_name=u'富文本链接跳转', blank=True)
    event = models.ForeignKey(SDEvent, related_name='event_parts', on_delete=models.CASCADE)

    def __str__(self):
        return self.text
